import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:mall/constant/app_parameters.dart';
import 'package:mall/modules/model/address_entity.dart';
// import 'package:mall/router/MobileRouteNames.dart';
import 'dart:convert';

import 'route_names.dart';

class NavigatorUtil {
  static goMallMainPage(BuildContext context) {
    // Application.router.navigateTo(context, MobileRouteNames.home,
    //     transition: TransitionType.inFromRight, replace: true);
    Get.toNamed(MobileRouteNames.home);
  }

  static goCategoryGoodsListPage(BuildContext context, String? categoryName, int? categoryId) {
    var categoryNameText = Uri.encodeComponent(jsonEncode(categoryName));
    // Application.router.navigateTo(
    //     context,
    //     MobileRouteNames.categoryGoods +
    //         "?${AppParameters.CATEGORY_NAME}=$categoryNameText&${AppParameters.CATEGORY_ID}=$categoryId",
    //     transition: TransitionType.inFromRight);

    Get.toNamed(MobileRouteNames.categoryGoods +
        "?${AppParameters.CATEGORY_NAME}=$categoryNameText&${AppParameters.CATEGORY_ID}=$categoryId");
  }

  static goGoodsDetails(BuildContext context, int? goodsId) {
    // Application.router.navigateTo(
    //     context, MobileRouteNames.goodsDetail + "?${AppParameters.GOODS_ID}=$goodsId",
    //     transition: TransitionType.inFromRight);
    Get.toNamed(MobileRouteNames.goodsDetail + "?${AppParameters.GOODS_ID}=$goodsId");
  }

  static goRegister(BuildContext context) {
    // Application.router.navigateTo(context, MobileRouteNames.register,
    //     transition: TransitionType.inFromRight);
    Get.toNamed(MobileRouteNames.register);
  }

  static goLogin() {
    // Application.router.navigateTo(context, MobileRouteNames.login,
    //     transition: TransitionType.inFromRight);
    Get.toNamed(MobileRouteNames.login_phone);
  }

  static goFillInOrder(int? cartId) {
    // Application.router.navigateTo(
    //     context, MobileRouteNames.fillInOrder + "?cartId=$cartId",
    //     transition: TransitionType.inFromRight);
    //+ "?cartId=$cartId
    Get.toNamed(MobileRouteNames.fillInOrder,arguments: {"cartId":cartId});
  }

  // isSelectType 0 点击以后不返回 1  点击以后返回
  static goAddress({ Function(AddressList address)? callback}) {
    Get.toNamed(MobileRouteNames.address, arguments: {'callback': callback});
  }

  static goAddressEdit(int? addressId) {
    // return Application.router.navigateTo(
    //     context, MobileRouteNames.editAddress + "?addressId=$addressId",
    //     transition: TransitionType.inFromRight);

    Get.toNamed(MobileRouteNames.editAddress,arguments: {"addressId":addressId});
  }

  static goCoupon(BuildContext context) {
    // return Application.router.navigateTo(context, MobileRouteNames.coupon,
    //     transition: TransitionType.inFromRight);

    Get.toNamed(MobileRouteNames.coupon);
  }

  static goSearchGoods(BuildContext context) {
    // return Application.router.navigateTo(context, MobileRouteNames.searchGoods,
    //     transition: TransitionType.inFromRight);

    Get.toNamed(MobileRouteNames.searchResult);
  }

  static goWebView(BuildContext context, String? titleName, String? url) {
    String encodeUrl = Uri.encodeComponent(jsonEncode(url));
    String encodeTitleName = Uri.encodeComponent(jsonEncode(titleName));
    // return Application.router.navigateTo(
    //     context, MobileRouteNames.webView + "?titleName=$encodeTitleName&url=$encodeUrl",
    //     transition: TransitionType.inFromRight);

    Get.toNamed(MobileRouteNames.webView + "?titleName=$encodeTitleName&url=$encodeUrl");
  }

  static goBrandDetail(BuildContext context, String? titleName, int? id) {
    String encodeTitleName = Uri.encodeComponent(jsonEncode(titleName));
    // return Application.router.navigateTo(
    //     context, MobileRouteNames.brandDetail + "?titleName=$encodeTitleName&id=$id",
    //     transition: TransitionType.inFromRight);

    Get.toNamed(MobileRouteNames.brandDetail + "?titleName=$encodeTitleName&id=$id");
  }

  static goProjectSelectionDetailView(BuildContext context, int? id) {
    // return Application.router.navigateTo(
    //     context, MobileRouteNames.projectSelectionDetail + "?id=$id",
    //     transition: TransitionType.inFromRight);

    Get.toNamed(MobileRouteNames.projectSelectionDetail + "?id=$id");
  }

  static goCollect(BuildContext context) {
    // return Application.router.navigateTo(context, MobileRouteNames.collect,
    //     transition: TransitionType.inFromRight);

    Get.toNamed(MobileRouteNames.collect);
  }

  static goAboutUs(BuildContext context) {
    // return Application.router.navigateTo(context, MobileRouteNames.aboutUs,
    //     transition: TransitionType.inFromRight);

    Get.toNamed(MobileRouteNames.aboutUs);
  }

  static goFeedBack(BuildContext context) {
    // return Application.router.navigateTo(context, MobileRouteNames.feedBack,
    //     transition: TransitionType.inFromRight);

    Get.toNamed(MobileRouteNames.feedBack);
  }

  static goFootPrint(BuildContext context) {
    // return Application.router.navigateTo(context, MobileRouteNames.footPrint,
    //     transition: TransitionType.inFromRight);

    Get.toNamed(MobileRouteNames.footPrint);
  }

  static goSubmitSuccess(BuildContext context) {
    // return Application.router.navigateTo(context, MobileRouteNames.submitSuccess,
    //     transition: TransitionType.inFromRight);

    Get.toNamed(MobileRouteNames.submitSuccess);
  }

  static goHomeAndClear(BuildContext context) {
    // return Application.router.navigateTo(context, MobileRouteNames.home,
    //     clearStack: true);

    Get.offAllNamed(MobileRouteNames.home);
  }

  static goHomeCategoryGoodsPage(BuildContext context, String? title, int? id) {
    var titleName = Uri.encodeComponent(jsonEncode(title));
    // return Application.router.navigateTo(
    //     context, MobileRouteNames.homeCategoryGoods + "?title=$titleName&id=$id",
    //     transition: TransitionType.inFromRight);

    Get.toNamed(MobileRouteNames.homeCategoryGoods + "?title=$titleName&id=$id");
  }

  static goOrderPage(BuildContext context, int initIndex) {
    // return Application.router.navigateTo(
    //     context, MobileRouteNames.orderPage + "?initIndex=$initIndex",
    //     transition: TransitionType.inFromRight);

    Get.toNamed(MobileRouteNames.orderPage + "?initIndex=$initIndex");
  }

  static goOrderDetailPage(BuildContext context, int? orderId) {
    // return Application.router.navigateTo(
    //     context, MobileRouteNames.orderDetailPage + "?orderId=$orderId",
    //     transition: TransitionType.inFromRight);

    Get.toNamed(MobileRouteNames.orderDetailPage + "?orderId=$orderId");
  }

  /**物流 */

  static goLogisticsPage(String orderID) {
    Get.toNamed(MobileRouteNames.logistics,arguments: {'orderID':orderID});
  }
  //售后
  static goAfterSalePage(String orderID) {
    Get.toNamed(MobileRouteNames.afterSale,arguments: {'orderID':orderID});
  }
}
